let kSize = 1024;
let mSize = 1024 * kSize;
let gSize = 1024 * mSize;
const util={
  install:function(Vue){
    /**
     * 判断参数是否为null或者undefined或者""或者" "；(除去0的情况)
     */
    Vue.prototype.isNullOrEmpty=function(obj){
      var flag = false;
      if (obj == null || obj == undefined || typeof (obj) == 'undefined' || obj === '') {
        flag = true;
      } else if (typeof (obj) == 'string') {
        //obj = obj.trim();//IE6和7不支持
        var spaceRe = new RegExp("^[ ]+$");
        if (spaceRe.test(obj)) {//为空
          flag = true;
        } else {//不为空
          obj = obj.toUpperCase();
          if (obj == 'NULL' || obj == 'UNDEFINED' || obj == '{}') {
            flag = true;
          }
        }
      }
      else {
        flag = false;
      }
      return flag;
    }
    /**
     * 判断参数是否为null或者undefined
     */
    Vue.prototype.isNull= function(obj){
      var flag = false;
      if (obj == null || obj == undefined || typeof (obj) == 'undefined') {
        flag = true;
      }
      return flag;
    }
    /**
     * 判断是否是空对象，若obj不是对象，则返回true
     * @param obj 对象
     * @returns {boolean}
     */
    Vue.prototype.isEmptyObject=(obj) =>{
      for (var name in obj) {
        if (obj.hasOwnProperty(name)) {
          return false;
        }
      }
      return true;
    }
  }
}

export default {

  /**
   * @description 数字转换单位 K M G 例子: 2048 => 2K
   * @param {Number} num 
   * @returns 
   */
  numberChangeHumanSee(num) {
    if (num > gSize) {
      return (num / gSize).toFixed(3) + "G";
    }

    if (num > mSize) {
      return (num / mSize).toFixed(3) + "M";
    }

    if (num > kSize) {
      return (num / mSize).toFixed(3) + "K";
    }
  },

  /**
   * @description 判断字符串是否为空
   * @param {string} obj 
   * @returns
   */
  isEmpty(obj) {
    if (typeof obj == "undefined" || obj == null || (obj + "").trim() == "") {
      return true;
    } else {
      return false;
    }
  },
  /**
   * @description map转list
   * @param {object} map 
   * @returns list
   */
  mapToList(map) {
    let list = [];
    for (let key in map) {
      list.push({
        key,
        value: map[key]
      });
    }
    return list;
  }
}
export {util}